<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
<head>
    <title>Javascript 二维码生成库：QRCode</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/>
    <!--<script src="/js/jquery.min.js"></script>-->
    <script src="/js/qrcode.min.js"></script>
    <script src="/js/axios.min.js"></script>
    <script src="/js/vue.min.js"></script>

</head>
<body>
<div id="qrcode" style="margin-top:15px;width:200px;margin: 0 auto">
    <p style="text-align: center">请扫描</p>
</div>

<script>
    var key = "key"
    var timer;
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        width: 200,
        height: 200
    });
    function getSessid() {
        axios.post('/common/getSessionId', {})
            .then(function (response) {
                var res = response.data;
                if (res.code == 200) {
                    key += ("=" + res.data.sessionId);
                    makeCode();
                }
                else {
                    alert(res.data.message);
                }
            })
            .catch(function (error) {
                console.log(error);
            });
    }
    function makeCode() {
        console.log(key + "--");
        qrcode.makeCode(key)
    }
    //是否使用微信登录
    function loopIslogin() {
        axios.post('/common/isLogin', {})
            .then(function (response) {
                var res = response.data;

                switch (res.code) {
                    case 200:window.clearInterval(timer);
                        alert("扫码成功");break;
                    case 202:window.clearInterval(timer);
                        alert(res.message);break;
                    default:console.log(res.message)
                }
            })
            .catch(function (error) {
                console.log(error);
            });
    }
    getSessid();
   timer= window.setInterval(loopIslogin,1000);

</script>
</body>
</html>
